package org.ww.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ww.common.utils.PageUtils;
import org.ww.common.utils.Query;
import org.ww.coupon.dao.SeckillSkuRelationDao;
import org.ww.coupon.entity.SeckillSkuRelationEntity;
import org.ww.coupon.service.SeckillSkuRelationService;

import java.util.List;
import java.util.Map;


@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity> implements SeckillSkuRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<SeckillSkuRelationEntity> wrapper = Wrappers.lambdaQuery();
        if(params.get("promotionSessionId") != null){
            wrapper.eq(SeckillSkuRelationEntity::getPromotionSessionId,params.get("promotionSessionId"));
        }
        IPage<SeckillSkuRelationEntity> page = this.page(
                new Query<SeckillSkuRelationEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<SeckillSkuRelationEntity> selectPromotionSessionIds(List<Long> ids) {
        LambdaQueryWrapper<SeckillSkuRelationEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.in(SeckillSkuRelationEntity::getPromotionSessionId,ids);
        return baseMapper.selectList(wrapper);
    }

}